package com.quanyan.dubbodemo.job;/*
package com.quanyan.scheduler.job;

import CacheApi;
import JedisCacheApi;
import TbWeichatAccount;
import TbWeichatAccountMapper;
import com.quanyan.weichat.api.WeichatServiceApi;
import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.List;
import java.util.Map;
import java.util.concurrent.Semaphore;

*/
/**
 * 
 * @ClassName : WeixinAcessTokenScheduler.java
 * @Description:
 * @Modification history Sep 12, 2015 4:12:54 PM
 * @Autor : chun.tu chuntu168@163.com
 * @Date : Sep 12, 2015 4:12:54 PM
 * @version :
 *
 *//*

public class WeixinAcessTokenScheduler extends QuartzJobBean {
    private Logger logger = Logger.getLogger(WeixinAcessTokenScheduler.class);

    @Autowired
    TbWeichatAccountMapper tbWeichatAccountMapper;
    
    private static int conThreadNum = 1;// 并发线程数,单线程，常新任务
    
    private static Semaphore semaphore = new Semaphore(conThreadNum);
    
    @Override
    protected void executeInternal(JobExecutionContext arg0)
        throws JobExecutionException {
        try {
            if (semaphore.availablePermits() < conThreadNum)
                return;
            semaphore.acquire();
            */
/** 刷新access_token *//*

            refreshAccessToken();
        }
        catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        finally {
            semaphore.release();
        }
    }

    public void refreshAccessToken() {
        List<TbWeichatAccount> weichatAccounts=tbWeichatAccountMapper.selectAllByType("H5");
        for(int i=0;i<weichatAccounts.size();i++){
            TbWeichatAccount weichatAccount=weichatAccounts.get(i);
            String appId=weichatAccount.getAppId();
            String securityKey=weichatAccount.getSecurityKey();
            WeichatServiceApi api = new WeichatServiceApi();
            Map<String, String> tokenMap = api.refreshToken(appId,securityKey);
            if (!tokenMap.get("result").equals("true")) {
                tokenMap = api.refreshToken(appId,securityKey);
            }
            CacheApi cacheApi = new JedisCacheApi();
            if (tokenMap.get("result").equals("true")) {
                cacheApi.hmset("token_" + appId, tokenMap);
            }
            String token=tokenMap.get("access_token");

            Map<String, String> ticktMap = api.refreshJsApiTiket(token);
            if (!ticktMap.get("result").equals("true")) {
                ticktMap = api.refreshJsApiTiket(token);
            }


            if (ticktMap.get("result").equals("true")) {
                cacheApi.hmset("ticket_" + appId, ticktMap);
            }
            String access_token=cacheApi.hget("token_" + appId, "access_token");
            String ticket=cacheApi.hget("ticket_" + appId, "ticket");
            System.out.println("access_token>>>>>>>>>>>>>:"+access_token);
            System.out.println("ticket>>>>>>>>>>>>>:"+ticket);
        }

    }



}
*/
